
<?php 
if(isset($_GET["id"]) && isset($_GET["page"]) )
{	
	$page = $_GET["page"];
	$idBill = $_GET["id"];
	include_once("../DataProvider.php");
	$sql = "select * from tbl_bills where IDBill = $idBill";
	$result = DataProvider::ExecuteQuery($sql);
	if($row = mysql_fetch_array($result))
	{
		
		$listGame = "";
		$sql1 = "select IDGame from tbl_detailbill where IDBill = $idBill";
		$result1 = DataProvider::ExecuteQuery($sql1);
		while($row1 = mysql_fetch_array($result1))
		{
			$listGame = $listGame. "," .$row1["IDGame"];
		}
		$listGame = substr($listGame,1);
		$time = strtotime($row["CreateDate"]);
		$date = date("d-m-Y",$time);
		?>
        <div>Mã hóa đơn: <?php echo $idBill; ?> </div>
		<div>Họ tên/Email: <?php echo $row["UserName"]; ?> </div>
	
		<div>Ngày đặt: <?php   echo $date; ?> </div>
		<table cellpadding="0" cellspacing="0" style="border-left:1px solid #E1E1E1;" width="700px">
		<tr >
			<th align="center" style="background-color:#C0DCC0;border-left:1px solid #E1E1E1;" >STT</th>
			<th align="center" style="background-color:#C0DCC0;border-left:1px solid #E1E1E1;" >Mã số</th>
			<th align="center" style="background-color:#C0DCC0;border-left:1px solid #E1E1E1;" >Hình</th>
			<th align="left" style="background-color:#C0DCC0;border-left:1px solid #E1E1E1;" >Tên game</th>
			<th align="right"style="background-color:#C0DCC0;border-left:1px solid #E1E1E1;" >Giá</th>
		</tr>
		<?php
	$sql2 ="SELECT * FROM tbl_games WHERE GameID IN (".$listGame." )";
	$result2 = DataProvider::ExecuteQuery($sql2);
	$tongsorecord = 0;
	if($result2)
		$tongsorecord = mysql_num_rows($result2);
	$y = 9;
	$start = ($page-1)*$y;
	$tongsotrang = ceil($tongsorecord/$y);
	$totalPrice = 0;
	if($tongsorecord == 0){
		//echo "Không có tin nào";	
	}
	else
	{
		while($row2 = mysql_fetch_array($result2))
		{
			$totalPrice+=$row2["Price"];
		}

		$sql3 ="SELECT * FROM tbl_games WHERE GameID IN (".$listGame." ) order by GameName limit $start,$y";
		$result3 = DataProvider::ExecuteQuery($sql3);
		$stt = $start;
		while($row3 = mysql_fetch_array($result3))
		{
			$stt++;
			?>
			<tr>
			<td align="center" width="40px"> <?php echo $stt; ?></td>
			<td align="center" width="70px"> <?php echo $row3["GameID"]; ?></td>
			<td  width="75px"><div style="background: url(<?php echo $row3["Artwork"]; ?>) no-repeat; background-size:70px; float:left; "><img src="img/mask175_t.png" height="70px" width="70px" /></div></td>
			<td align="left" nowrap="wrap"><?php echo $row3["GameName"]; ?></td>
			<td align="right"><?php echo number_format($row3["Price"], 0, '.', ',');?> VNĐ</td>
		   
		</tr>
<?php	}
	}
	
?>
<tr>
    <td colspan="4" align="right"> Tổng tiền:&nbsp;&nbsp;
    </td>
    <td align="right">
    <?php echo number_format($totalPrice,0,".",",") ;?> VNĐ
    </td>
</tr>
<tr>
<td align="right" colspan="5" bgcolor="#CCCCCC"><span style=" margin-right:1px;color:#000; background-color:#fff;border:solid;  border-color:#000; border-width:2px;">&nbsp;Trang <?php echo $page."/".$tongsotrang ?>&nbsp;</span>
<?php

       			if($page == 1)
				{echo"<span class='active' style='color:#000; background-color:#fff;border:solid; border-color:#000; border-width:2px;'><<</span>";}
				else
				{
				echo"<span class='paging'><a style='text-decoration:none;' href='#1' onclick='javascript:loadBill(1,".$idBill.");'><< </a> </span>";}
			for($i=1;$i<=$tongsotrang;$i++){
				
				if($i == $page){
				 echo "<span class='active' style=' margin-right:1px; ; background-color:#fff;border:solid; border-color:#000; border-width:2px;'>$i</span>";	
				}else{
					echo "<span class='paging'><a style='text-decoration:none;' href='#$i' onclick='javascript:loadBill($i,".$idBill.");'> $i</a>  </span>";	
				}
			}
			if($page == $tongsotrang)
				{echo"<span class='active' style='  background-color:#fff;border:solid; border-color:#000; border-width:2px;'>>></span>";}
				else
				{
				echo"<span class='paging' ><a style='text-decoration:none;' href='#$i' onclick='javascript:loadBill($tongsotrang,".$idBill.");'> >> </a></span>";
				}
}}
?>
</table>